<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>本地存储</title>
	</head>
	<body>
		<input type="text" id="inp1">
		<button onclick="changCun()">长时间存放</button>
		<button onclick="shortCun()">短时间存放</button>
		<button onclick="quChangCun()">长时间存放读取</button>
		<button onclick="qushortCun()">短时间存放读取</button>
		<script>
			function changCun () {
				// var v1 = document.getElementById("inp1").value
				var v1 = {
					name:"张三",
					age:18
				}
				localStorage.setItem("longTime",JSON.stringify(v1))
			}
			function quChangCun(){
				console.log(localStorage.getItem("longTime"));
				console.log(JSON.parse(localStorage.getItem("longTime")));
			}
			function shortCun () {
				var v1 = document.getElementById("inp1").value
				sessionStorage.setItem("shortTime",v1)
			}
			function qushortCun(){
				console.log(sessionStorage.getItem("shortTime"));
			}
			//存取的内容只支持字符串
			
		</script>
	</body>
</html>